<template>
  <el-dialog :title="'选择入住登记单'" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true">
    <el-form :model="dataForm" @keyup.enter.native="getDataList()" :inline="true">
<!--      <el-form-item label-width="0" v-if="isAuth('hotel:hotelseller:list')">
        <el-select
          multiple
          collapse-tags
          clearable
          style="width:180px;"
          v-model="sellerIds"
          filterable
          remote
          reserve-keyword
          @change="selectSeller"
          placeholder="商家名称"
          :remote-method="remoteMethod"
          :loading="loading"
        >
          <el-option v-for="item in platformSeller" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label-width="0">
        <el-select v-model="dataForm.state" size="small">
            <el-option label="全部" :value="99"></el-option>
            <el-option label="正常入住" :value="1"></el-option>
            <el-option label="未结退房" :value="2"></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label-width="0">
        <el-input v-model="dataForm.sysNo" placeholder="入住单号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-delete" @click="clearShaiXuan">清空筛选</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getDataList()">{{ $t('Common.Query') }}</el-button>
      </el-form-item>
    </el-form>

    <el-table
      style="width: 100%"
      row-key="id"
      ref="unitedHouseList"
      default-expand-all
      :data="unitedHouseList"
      tooltip-effect="dark"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column label="房间">
        <template slot-scope="scope">
          {{ scope.row.hotelFloorRoomEntity.roomSign }}{{ scope.row.hotelFloorRoomEntity.roomNum }}
        </template>
      </el-table-column>
      <el-table-column label="单号">
        <template slot-scope="scope">
          <a type="text" @click="toAccounting({ singleId: scope.row.singleId }, '1')">{{ scope.row.sysNo }}</a>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.state == 0">已结退房</span>
          <span v-if="scope.row.state == 1">正常入住</span>
          <span v-if="scope.row.state == 2">未结退房</span>
          <span v-if="scope.row.state == 3">联房退房</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="selThis(scope.row)">选择</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="margin-top: 15px;text-align: right;"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
  </el-dialog>
</template>

<script>
import moment from 'moment';
export default {

  data() {
    return {
      pickerOptions: {

      },
      loading: false,
      visible: false,
      shaixuan: false,
      currDate: moment().format('YYYY-MM-DD'),
      unitedHouseList: [],
      platformSeller: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      sj:{
        one:0,
        two:0,
        three:0,
        four:0,
        five:0,
      },
      dataForm: {
        state: 99,
        externalNo: '',
        sysNo: '',
        checkinType: '',
        sourceType: '',
        ruzhu1:'',
        ruzhu2:'',
        lidian1:'',
        lidian2:'',
        creat1:'',
        creat2:'',
      },
      sellerIds:[],
    };
  },
  components: {},
  activated() {
    this.getDataList();
    this.remoteMethod();

  },
  methods: {
    selThis(row){
      this.visible = false;
      this.$emit('selctClosing', row);
    },
    //清空筛选
    clearShaiXuan(){
      Object.assign(this.dataForm, this.$options.data().dataForm)
      this.getDataList();
    },
    selectSeller(id, value) {
      this.getDataList()
    },
    //加载平台商家数据
    remoteMethod(query) {
      if(this.isAuth('hotel:hotelseller:list')){
        this.loading = true;
        this.$http({
          url: this.$http.adornUrl("/hotel/hotelseller/platformSeller"),
          method: "get",
          params: this.$http.adornParams({
            sellerName: query
          })
        }).then(({ data }) => {
          this.loading = false;
          if (data && data.code === 0) {
            this.platformSeller = data.page.list;
          } else {
            this.$message.error(data.msg);
          }
        });
      }
    },
    init() {
      this.visible = true;
      this.getDataList();
      this.$nextTick(() => {

      });
    },
    getDataList() {

      var ids = ""
      if(this.sellerIds){
        this.sellerIds.forEach((item,index) =>{
          ids+=item+","
        })
        ids = ids.substring(0,ids.length-1)
      }
      var params = {
        page: this.pageIndex,
        limit: this.pageSize,
        ids:ids,
        ...this.dataForm,
      }
      this.$http({
        url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/seller_rooms`),
        method: 'get',
        params: this.$http.adornParams(params)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          console.log(data);
          this.unitedHouseList = data.data.list;
          this.totalPage = data.data.totalCount;
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    }
  }
};
</script>

<style>
.dl_drop {
  color: rgba(0, 0, 0, 0.65);
  z-index: 999;
  border-radius: 4px;
  overflow: hidden;
}
.dl_drop dd {
  padding: 0 15px;
  font-size: 13px;
  height: 35px;
  line-height: 35px;
  cursor: pointer;
  white-space: nowrap;
  margin: 0px;
}
</style>
